package ooday03;
/** 引用类型数组的演示 */
public class RefArraydDemo {
    public static void main(String[] args) {
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",5,"黑");//给引用类数组赋值 new 变量名 ()
        dogs[1] = new Dog("小白",5,"白");
        dogs[2] = new Dog("小蓝",5,"蓝");
        System.out.println(dogs[0].name);//第一个狗的名字
        dogs[1].age = 4;//修改第2个狗的名字
        dogs[2].swim();//第三个狗在游泳
        for (int i = 0; i <dogs.length ; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }

        Chick[] chick = new Chick[2];
        chick[0] = new Chick("小红",5,"红");
        chick[1] = new Chick("小紫",5,"紫");
        for (int i = 0; i <chick.length ; i++) {
            System.out.println(chick[i].name);
            chick[i].eat();
        }


        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金",5,"金");
        fish[1] = new Fish("大金",5,"金");
        fish[2] = new Fish("小绿",5,"绿");
        fish[3] = new Fish("小花",5,"花");
        for (int i = 0; i < fish.length ; i++) {
            fish[i].swim();
        }


    }
}
